import utils from '@/utils';

export default class Request {
    data = {};
    url = '';
    method = '';
    header = {};
    constructor({
        url = '',
        method = 'POST',
        data = {},
        header = { 'content-type': 'application/x-www-form-urlencoded' }
    } = {}) {
        this.url = url;
        this.method = method;
        this.data = data;
        this.header = header;
    }
    send() {
        return utils
            .promisify(uni.request)({
                url: this.url,
                data: this.data,
                method: this.method,
                header: this.header
            })
            .catch(err => {
                console.log(err);
                return utils.fail('网络连接异常').then(() => Promise.reject(err));
            });
    }
}